/**
 * VYPe11 Project
 * VYPe11 language compiler.
 * Authors: Jozef Lang (xlangj01), 
 * 			Zoltan Zemko (xzemko01)
 * 2011
 */
package cz.vutbr.fit.VYPe.team18.VYPe11.nodes.expression.terminal;

import java.io.IOException;

import cz.vutbr.fit.VYPe.team18.VYPe11.exception.SematicException;
import cz.vutbr.fit.VYPe.team18.VYPe11.nodes.IdentifierNode;
import cz.vutbr.fit.VYPe.team18.VYPe11.nodes.data_type.DataType;
import cz.vutbr.fit.VYPe.team18.VYPe11.sematic.declared.Variable;

public class IdentifierExpressionNode extends TerminalExpression {
	private IdentifierNode identifier;
	
	public IdentifierExpressionNode(
						IdentifierNode identifier) {
		this.identifier=identifier;
	}

	public IdentifierNode getIdentifier() {
		return identifier;
	}
	
	public DataType getType() throws SematicException {
		if(expressionType!=null)
			return expressionType;
		Variable var =declarationLevels.findVariableById(identifier.getId());
		expressionType=var.getType();
		return expressionType;
	}

	@Override
	public void generateTAC() throws IOException {
		writeTAC("=", identifier.getId(), "", "_t"+tacCounter.getNextTermIndex());	
	}
}
